<?php
namespace app\common\model;
use app\common\model\Info as InfoModel;
class PlatformApiLog extends Base
{
    protected $table = 'platform_api_logs';

    protected static function init()
    {

    }

    public function getCreateTimeLabelAttr($value, $data)
    {
        if (empty($data['create_time'])) {

            return '';
        }

        return date('Y-m-d H:i:s', $data['create_time']);
    }

    public function getStatusTimeLabelAttr($value, $data)
    {
        if (empty($data['status_time'])) {

            return '';
        }

        return date('Y-m-d H:i:s', $data['status_time']);
    }

    public function getChannelIdLabelAttr($value, $data)
    {
		$info = Info::get(array('id' => $data['info_id']));
        $channel = Channel::get(array('id' => $info['channel_id']));

        if (empty($channel)) {
            return '未知';
        }

        return $channel['name'];
    }
	
	public function getPlatformIdLabelAttr($value, $data)
    {
        $platform = Platform::get(array('id' => $data['platform_id']));

        if (empty($platform)) {
            return '未知';
        }

        return $platform['name'];
    }

    public function getPlatformTypeLabelAttr($value, $data)
    {
        if ($data['platform_type'] == 1) {
           return '独享';
        }

        if ($data['platform_type'] == 2) {
            return '共享';
        }

        return '未知';
    }

    public function getIdCardAttr($value, $data)
    {
        $info = Info::where('id', $data['info_id'])->find();

        if (empty($info)) {
            return '未知';
        }


        if (!isset($info['id_card']) || empty($info['id_card'])) {
            return '';
        }

        if ($data['status'] == 1) {
            return $info['id_card'];
        }

        $id_card = substr($info['id_card'], 0, 4) . str_repeat('*', strlen($info['id_card']) - 8). substr($info['id_card'],-4);
        return $id_card;

    }

    public function getApplyNameAttr($value, $data)
    {
        $info = Info::where('id', $data['info_id'])->find();

        if (empty($info)) {
            return '未知';
        }

        return $info['apply_name'];
    }

    public function getPhoneAttr($value, $data)
    {
        if (!empty($data['member_id'])){
            $member = Member::where('id', $data['member_id'])->find();
            if (empty($member)) {
                return '未知';
            }

            if ($data['status'] == 1) {
                return $member['phone'];
            }
            return substr($member['phone'], 0, 3) . str_repeat('*', strlen($member['phone']) - 7). substr($member['phone'],-4);

        }
        //        return $data['info_id']; 信息
        $info = InfoModel::where('id',$data['info_id'])->find();
//        $member = Member::where('id', $data['member_id'])->find();
        if (empty($info)) {
            return '未知';
        }

        if ($data['status'] == 1) {
            return $info['phone'];
        }

        return substr($info['phone'], 0, 3) . str_repeat('*', strlen($info['phone']) - 7). substr($info['phone'],-4);
    }

    public function getStatusArrAttr($value, $data)
    {
        switch ($data['status']) {
            case 1:
                $result['status_label'] = '成功推送';
                $result['status_class'] = 'layui-btn-default';
                break;
            case 0:
				$result['status_label'] = '推送失败';
				$result['status_class'] = 'layui-btn-danger';
				break;
                break;
            default:
                $result['status_label'] = '未返回';
                $result['status_class'] = 'layui-btn-primary';
                break;
        }
        return $result;
    }



}